﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShotURL.Models;


namespace ShotURL.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {

            DataManager db = new DataManager();
            ViewData.Model = db;


            ViewBag.Title = "Моя страница";
            return View();
        }

        [HttpGet]
        public ActionResult ClickUrl(Guid id)
        {
            DataManager db =new DataManager();
            db.SetClickUrl(id);
            return Redirect(db.GetInfoKey(id).ShotUrl.LongUrl);
        }
        [HttpPost]
        public ActionResult AddShotURL(string url)
        {
            TransfomUrl tr=new TransfomUrl();
            DataManager db = new DataManager();
            ShotUrl obj =new ShotUrl();
            InfoKey Obj_info =new InfoKey();
            obj.LongUrl = url;
            obj.ShotKey = tr.Transfom(url);
            obj.UserId = Guid.NewGuid();
            obj.ShoturlId = Guid.NewGuid();
            Obj_info.InfoID = Guid.NewGuid();
            Obj_info.ShotUrlId = obj.ShoturlId;
            Obj_info.ClickShotUrl = 0;
            obj.InfoKeys.Add(Obj_info);
            db.AddShotUrl(obj);
            return RedirectToAction("Index");
        }

    }
}
